//---------------------------------------------------------------------------

#pragma hdrstop
#include "WorkThread.h"
#pragma package(smart_init)
__fastcall TWorkThread::TWorkThread(char* ThreadName,bool CreateSuspended,TThreadPriority priority )
	: TThread(CreateSuspended)
{
	SetName(ThreadName);
	FreeOnTerminate=true;
	Priority=priority;
}
//---------------------------------------------------------------------------
void TWorkThread::SetName(char* ThreadName)
{
	
	info.dwType = 0x1000;
	info.szName = ThreadName;
	info.dwThreadID = -1;
	info.dwFlags = 0;

	__try
	{
		RaiseException( 0x406D1388, 0, sizeof(info)/sizeof(DWORD),(DWORD*)&info );
	}
	__except (EXCEPTION_CONTINUE_EXECUTION)
	{
	}
}
//---------------------------------------------------------------------------
void __fastcall TWorkThread::Execute()
{
	bool i=true;
	DoOnStart(this);
	try{
	if(Task)Task();
	}catch(Exception &e){
	   i=false;
	}

	DoOnFinished(this,(TObject *)&i);
}

void __fastcall TWorkThread::DoOnStart(TObject *Sender){
	if(FOnStart)FOnStart(Sender);
}

void __fastcall TWorkThread::DoOnFinished(TWorkThread *thread,TObject *ReturnValue){
	if(FOnFinished){
		FOnFinished(thread,ReturnValue);
	}
}
//---------------------------------------------------------------------------

